import { http } from "@gonsin/gview";
import qs from "qs";

const userApiUrl = {
	// SpringBoot GView 内置时使用
	// loginUrl: "/api/user/handle_login",
	// menuUrl: "/restapi/s09/gview/menus",
	loginUrl: "/api/user/login",
	menuUrl: "/api/menus/getAuthorizedMenus",
	registerUrl: "/api/s11/user/register/",
	getUserMessage: "/restapi/userMessages/",
	getUserEdifice: "/restapi/edifice",
	getWebSiteSet: "/api/webSiteSet/getWebSiteSet",
	getEdifice: "/restapi/edifice",
};

export function userLoginApi(params: { username: string; password: string }) {
	return <any>http.post(userApiUrl.loginUrl, qs.stringify(params));
}

export function userRegisterApi(params: any) {
	return <any>http.post(userApiUrl.registerUrl, params);
}

export function getMenusApi() {
	// SpringBoot GView 内置时使用
	// return <any>http.get(userApiUrl.menuUrl);
	return <any>http.post(userApiUrl.menuUrl);
}

export function getUserMessageApi(userMessageKey: string) {
	return <any>http.post(`${userApiUrl.getUserMessage}/${userMessageKey}`);
}

export function getUserEdificeKeyApi(username: string) {
	return <any>http.post(`${userApiUrl.getUserEdifice}`, {
		username: username,
	});
}

export function getWebSiteSetApi() {
	return <any>http.get(`${userApiUrl.getWebSiteSet}`);
}

export function getEdificeApi(edificeKey: string) {
	return <any>http.post(`${userApiUrl.getEdifice}/${edificeKey}`);
}
